<template>
	<view class="body">
		<xk-header title="物业摘牌申请 - 新增"></xk-header>
		<view class="util-bar">
			<view class="estate-box">
			<u--form
			labelPosition="left"
			:model="formdata"
			:rules="rules"
			ref="uviewForm"
			>
				<u-form-item
					label="联系人:"
					prop="apply_user_name"
					borderBottom
					required
					ref="apply_user_name"
					labelWidth="100"
				>
				<u--input v-model="formdata.apply_user_name" placeholder="请输入联系人" border="none"></u--input>
				</u-form-item>
				<u-form-item
					label="申请人单位:"
					prop="apply_dept_name"
					borderBottom
					required
					ref="apply_dept_name"
					labelWidth="100"
				>
				<u--input v-model="formdata.apply_dept_name" placeholder="请输入申请人单位" border="none"></u--input>
				</u-form-item>
				<u-form-item
					label="物业信息:"
					prop="apply_dept_name"
					borderBottom
					required
					ref="apply_dept_name"
					labelWidth="100"
					rightIcon="arrow-right"
				>
				<view @click="editBuild" v-if="pi_delist_id">
					<view v-if="assetsPropertyIds.length>0">已添加<text style="color:#FF0000;">{{assetsPropertyIds.length}}</text>处物业(点击查看)</view>
					<view v-else style="color:#2c72ff;display: flex;">点击重新选择物业信息 <u-icon slot="right" name="arrow-right"></u-icon></view>

				</view>
				<view @click="editBuild" v-else>
					<view v-if="assetsPropertyIds.length>0">已添加<text style="color:#FF0000;">{{assetsPropertyIds.length}}</text>处物业(点击查看)</view>
					<view v-else style="color:#2c72ff;display: flex;">请点击选择物业信息 <u-icon slot="right" name="arrow-right"></u-icon></view>

				</view>
				</u-form-item>
				<u-form-item
					label="电话*:"
					prop="apply_phone"
					borderBottom
					required
					ref="apply_phone"
					labelWidth="100"
				>
				<u--input v-model="formdata.apply_phone" placeholder="请输入电话" border="none"></u--input>
				</u-form-item>
				<u-form-item
					label="邮编:"
					prop="apply_emailm"
					borderBottom
					ref="item1"
					labelWidth="100"
				>
				<u--input v-model="formdata.apply_emailm" placeholder="请输入邮编" border="none"></u--input>
				</u-form-item>
				<u-form-item
					label="保证金(元):"
					prop="caution_money"
					borderBottom
					required
					ref="item1"
					labelWidth="100"
				>
				<u--input v-model="formdata.caution_money" placeholder="请输入保证金" border="none" type="number"></u--input>
				</u-form-item>
				<u-form-item
					label="地址:"
					prop="apply_address"
					borderBottom
					required
					ref="item1"
					labelWidth="100"
				>
				</u-form-item>
				<u--textarea v-model="formdata.apply_address" placeholder="请输入地址" height="50" count confirmType="done"></u--textarea>

				<u-form-item
					label="备注:"
					prop="apply_remark"
					borderBottom
					ref="item1"
					labelWidth="100"
				>

				</u-form-item>
				<u--textarea v-model="formdata.apply_remark" placeholder="请输入备注信息" height="50" count confirmType="done"></u--textarea>
			</u--form>
			</view>
		</view>
		<view class="common-bottom-view">
			<view v-if="pi_delist_id" class="common-btn btn" @click="doneSubmit">修改</view>
			<view v-else class="common-btn btn" @click="doneSubmit">提交</view>
		</view>
		<view style="height:100px;"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pi_delist_id:'',
				assetsPropertyIds: [],
				formdata:{
					"apply_user_name":'',
					"apply_dept_name":'',
					"apply_phone":'',
					"apply_emailm": "",
					"apply_address": "",
					"caution_money": "",
					"apply_remark": "",
					"isSubmit": false,
					"dets": []
				},
				rules: {
					'apply_user_name': {
						type: 'string',
						required:true,
						message: '请填写联系人',
						trigger:['blur','change']
					},
					'apply_dept_name': {
						type: 'string',
						required:true,
						message: '请填写申请人单位',
						trigger:['blur','change']
					},
					'apply_phone': {
						type: 'string',
						required:true,
						message: '请填写电话号码',
						trigger:['blur','change']
					},
					'caution_money': {
						type: 'number',
						required:true,
						message: '请填写保证金',
						trigger:['blur','change']
					},
				},
			}
		},
		onLoad(opt) {
			if(opt.pi_delist_id){
				this.pi_delist_id = opt.pi_delist_id
				console.log(this.pi_delist_id)
				this.getDetail()
			}
		},
		onShow(){
			console.log('assetsPropertyIds',this.assetsPropertyIds);
		},
		mounted(){
			this.$util.getHeightWithTopEl(".util-bar").then(height => {
				this.scrollViewHeight = height;
			});
		},
		methods: {
			editBuild(){
				uni.$off('getBuildInfo')
				uni.$on('getBuildInfo', (res)=>{
					console.log('getBuildInfo:',res);
					this.assetsPropertyIds = res
				});
				uni.navigateTo({
					url: '/pagesA/estate-delisting/wuye-info?ids=' + JSON.stringify(this.assetsPropertyIds)
				})
			},
			getDetail(){
				this.$api.get_delistData_getDelistDetail(this.pi_delist_id).then((res)=>{
					console.log(res.delistData_getDelist)
					this.formdata=res.delistData_getDelist;
				});
			},
			cancelDate(){
				this.showDate=false;
			},
			doneSubmit(){
				this.$refs.uviewForm.validate().then(res => {
					//uni.$u.toast('校验通过')
					if(this.formdata.apply_address==''){
						uni.$u.toast('请输入地址');
						return false;
					}
					this.$util.confirm({
						content: "确定提交新增申请？",
						confirmText: "确定"
					}).then(isConfirm => {
						this.formdata.dets=this.assetsPropertyIds;
						console.log("formdata.dets:",this.formdata.dets)
						if (isConfirm) {
							this.$util.post({
								url: "app/piDelist/apply",
								data: this.formdata,
							}).then(res => {
								uni.redirectTo({
									url: '/pagesA/estate-delisting/estate-delisting-list'
								})
							})

						}
					})
				}).catch(errors => {
					uni.$u.toast('请输入必填项')
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.body{
	background:#F8F8F8;
}
.estate-box{
	background:#FFFFFF;
	padding:10px 10px 30px 10px;
	margin:10px;
	border-radius:6px;
}

.loadText{
	padding:5px 0px 20px 0px;
}
</style>
